﻿using System.Threading.Tasks;

namespace Letter.IO.Channels;

partial class Channel<T>
{
    sealed class ChannelWriter : IChannelWriter<T>
    {
        public ChannelWriter(Channel<T> channel)
        {
            this.Channel = channel;
        }

        private Channel<T> Channel
        {
            get;
        }

        public bool Active
        {
            get { return this.Channel.Writable; }
        }
        
        public long Count
        {
            get { return this.Channel.count; }
        }
        
        public ValueTask<bool> TryWriteAsync(T o)
        {
            return this.Channel.TryWriteAsync(o);
        }
        
        public void Complete()
        {
            this.Channel.Release();
        }
    }
}
